package wxk.interview.spring.ioc.beans;

import org.springframework.beans.factory.FactoryBean;

/**
 * @author wangxuekai
 * @version 2.2
 * @Date 2017/3/28.
 * @since 2.2
 */
public class MyFactoryBean implements FactoryBean<Person> {

    private String info;

    public String getInfo() {
        return info;
    }

    public void setInfo(String info) {
        this.info = info;
    }

    public Person getObject() throws Exception {
        String[] args = info.split(",");
        String idNo = args[0];
        String name = args[1];
        Integer gender = Integer.valueOf(args[2]);
        return new Person(idNo,name,gender);
    }

    public Class<?> getObjectType() {
        return Person.class;
    }

    public boolean isSingleton() {
        return false;
    }

    @Override
    public String toString() {
        final StringBuilder sb = new StringBuilder("MyFactoryBean{");
        sb.append("info='").append(info).append('\'');
        sb.append('}');
        return sb.toString();
    }
}
